package com.business.task;

import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.business.commons.date.DateFormat;
import com.business.model.taskBat.TaobaoImportMsg;
import com.business.service.taskBat.TaobaoImportMsgService;

/**
 * spring task 定时任务测试，适用于单系统
 * 注意：不适合用于集群
 * @author L.cm
 */
@Component
public class TaobaoImportMsgBatTask {
	protected Logger logger = LogManager.getLogger(getClass());
	
	@Autowired private TaobaoImportMsgService taobaoImportMsgService;
	
	//@Scheduled(cron = "0 5/20 * * * ?")
	
	@Scheduled(fixedDelay = 6000)
	public void cronTest() {
		logger.debug("\n\n跑批任务开始。。。。。。" + DateFormat.getCurrentTime());
		Integer page=1;
		Integer rows=300;
		TaobaoImportMsg taobaoImportMsg = new TaobaoImportMsg();
		taobaoImportMsg.setCheckJudge(0);
        EntityWrapper<TaobaoImportMsg> ew = new EntityWrapper<TaobaoImportMsg>(taobaoImportMsg);
        Page<TaobaoImportMsg> pages = new Page<TaobaoImportMsg>(page,rows,"commitDate");
        pages.setAsc(true);
        pages = taobaoImportMsgService.selectPage(pages, ew);
        List<TaobaoImportMsg> list = pages.getRecords();
        if(null != list){
        	logger.info("list size:"+list.size());
        }else{
        	logger.info("list is null!");
        }
        for(TaobaoImportMsg t : list) {
        	taobaoImportMsgService.checkAndJudge(t);
        	taobaoImportMsgService.updateById(t);
        }
		
		logger.debug("跑批任务结束。。。。。。" + DateFormat.getCurrentTime());
	}
}
